# main.py
from tkinterUI import main

import sys,os
sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
from protocol.decorators import edp_service, instant
from tract_point import Tractor

@edp_service
class CVP:
    name = "CVP"
    desc = "2d-insect-track-system"
    category = "VideoProcessing"
    tasks = [
        'launch_cvp:Void->Void',
        'tract_point:(FilePath, Int)->PointI'
    ]
    def launch_cvp(self):
        main("release")
    def tract_point(self, inputs):
        vp = inputs[0]
        idx = inputs[1]
        import cv2
        cap = cv2.VideoCapture(vp)
        cap.set(1, idx)
        ret, frame = cap.read()
        if not ret:
            raise Exception('invalid video')
        trc = Tractor()
        trc.tractPoint(frame)
        return trc.gbPoint

if __name__ == "__main__":
    vp = r"C:\Users\songy\Desktop\fyp-songy-2025-05-17\videos\fyp_20250326171146.mp4"
    CVP().tract_point((vp,0))
    CVP().tract_point((vp,0))
    # CVP.app.run(port=8090)

# author - Song Yufan from Beijing Institute of Technology
